#! /usr/bin/env python
from sqlite3 import dbapi2 as sqlite

flist = ["Date", "First", "Second", "Third", "Fourth", "Fifth","Powerball"]

conn = sqlite.connect("lotto-hist")
conn.row_factory = sqlite.Row
curs = conn.cursor()

for i in range(1,59):
	new_table = "whiteball_" + str(i)
	conn.execute('create  table %s (date_index) ' % (new_table) )
	curs.execute("select * from history where first=? or second=? or third=? or fourth=? or fifth=? order by date",(i,i,i,i,i))
	rows = curs.fetchall()
	for row in rows:
		date_drawn = row[0]
		curs.execute("insert into %s values (?)" %(new_table), (date_drawn[0]))
		

#date_in=raw_input("Enter a number: ")
#curs.execute("select * from history where first=? or second=? or third=? or fourth=? order by date",(date_in,date_in,date_in,date_in,))
#rows= curs.fetchall()
#count = 0
#for row in rows:
#	print "Date: "+ str(row['date']) + "\nNumbers: "+ str(row['first']) + " " + str(row['second']) + " " + str(row['third'] ) + " " + str(row['fourth']) + " " + str(row['fifth'])
#	count += 1
#	
#print str(date_in) + " occurred " + str(count) + " times"
